package com.kedacom.freedomLabel.viewmodel;

import com.kedacom.freedomLabel.AppExecutors;
import com.kedacom.freedomLabel.Options;
import com.kedacom.freedomLabel.base.BaseViewModel;
import com.kedacom.freedomLabel.initdata.bean.EventBusMessage;
import com.kedacom.freedomLabel.initdata.bean.Post;
import com.kedacom.freedomLabel.initdata.bean.RubbishBean;
import com.kedacom.freedomLabel.model.db.AppDatabase;
import com.kedacom.lego.message.LegoMessageManager;

import java.util.ArrayList;
import java.util.List;

public class DataAnalysisViewModel extends BaseViewModel {


    public void getOneDate(long startTime,long endTime) {

        AppExecutors.getInstance().queryIO()
                .submit(() -> {
                    List<RubbishBean> rubbishBeanList = AppDatabase.getInstance().getRubbishDao()
                            .getOneDayPost(startTime,endTime);
                    sendMessage("getBusinessSuccess",rubbishBeanList);
                });


    }
    public void deleteOneDate(long startTime,long endTime) {

        AppExecutors.getInstance().queryIO()
                .submit(() -> {
                    AppDatabase.getInstance().getRubbishDao()
                            .deleteOneDayPost(startTime,endTime);
                    List<RubbishBean> rubbishBeanList =new ArrayList<>();
                    rubbishBeanList.clear();
                    sendMessage("getBusinessSuccess",rubbishBeanList);
                });


    }
    public void deleteOne(RubbishBean rubbishBean) {

        AppExecutors.getInstance().queryIO()
                .submit(() -> {
                    AppDatabase.getInstance().getRubbishDao()
                            .delete(rubbishBean);
                    LegoMessageManager.getInstance().sendMessage(Options.MSG_POST_SUCCESS, new EventBusMessage(7, "删除成功", "删除一个数据", 1));
                });


    }

}
